﻿function Register() {
    var sign = "callback=" + $("#callback").val() + "&merchantNo=" + $("#merchantNo").val() + "&timestamp=temp&userName=" +
        $("#userName").val();
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            var time = data.substring(0, 14);
            var sign = data.substring(14, data.length);
            $("#timestamp").val(time);
            $("#sign").val(sign);
            $("#Register").submit();
        },
        data: "sign=" + sign, 
    });
}

//格式化时间
function TimeFormat() {
    var myDate = new Date();
    var time = "";
    time = time + myDate.getFullYear();
    var month = myDate.getMonth() + 1;
    if (month < 10) {
        month = "0" + month;
    }
    time = time + month;
    var day = myDate.getDate();
    if (day < 10) {
        day = "0" + day;
    }
    time = time + day;
    var hour = myDate.getHours();
    if (hour < 10) {
        hour = "0" + hour;
    }
    time = time + hour;
    var minute = myDate.getMinutes();
    if (minute < 10) {
        minute = "0" + minute;
    }
    time = time + minute;
    var second = myDate.getSeconds();
    if (second < 10) {
        second = "0" + second;
    }
    time = time + second;
    return time;
}

//查询个人的资金
function ChaXun(){
    $.ajax({
        url: "/Account/SelectSftUserBalance",
        type: "Post",
        success: function (data) {
            var obj = JSON.parse(data);
            if (obj.errorCode == "200") {
                $("#sftUserAmount").val(obj.totalAmount);
            }
            else {
                alert("数据错误");
            }
        },
        data: "merchantNo=" + "708732",
    });
}

//查询商户的资金
function ChaXunShangHu() {
    $.ajax({
        url: "/Account/SelectsftShangHu",
        type: "Post",
        success: function (data) {
            var obj = JSON.parse(data);
            if (obj.errorCode == "200") {
                $("#sftMerchantAmount").val(obj.availableAmount);
            }
            else {
                alert("数据错误");
            }
        },
        data: "merchantNo=" + "708732" + "&relatedMerchantNo=" + "708732",
    });
}

//跳转首页
function ShouYe() {
    var sign = "merchantNo=" + $("#ShouYemerchantNo").val() + "&timestamp=" + "temp" + "&userName=" + $("#ShouYeuserName").val();
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            var time = data.substring(0, 14);
            var sign = data.substring(14);
            $("#ShouYetimestamp").val(time);
            $("#ShouYesign").val(sign);
            $("#ShouYeForm").submit();
        },
        data: "sign=" + sign,
    });
}

//解约用户代扣协议
function JieChu() {
    $.ajax({
        url: "/Account/JieChuDaiKou",
        type: "Post",
        success: function (data) {
            alert(data);
        },
        data: "merchantNo=" + "708732" + "&userName=" + "hjhang_sunmin",
    });
}

//平台发标 /p2pBid/{merchantNo}-{issueBidNo}
function FaBiao() {
    $.ajax({
        url: "/Account/FaBiao",
        type: "Post",
        success: function (data) {
            alert(data);
        },//金额，平台发标编号唯一 201505201234
        data: "debitAmount=" + "100.00" + "&issueBidNo=" + "201505201235" + "&merchantNo=" + "708732" + "&revenueRate=" + "3.00" +
            "&issueBidType=" + "1" + "&debitUserName=" + "hjhang_sunmin" + "&deadline=" + "100" + "&repaymentMode=" + "3" +
            "&rewardAmount=" + "1.00",
    });
}

//用户投标
function TouBiao() {
    //先将顺序拼接好
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#TouBiaotimestamp").val(timestamp);
    var sign = "callback=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&creditAmount=1.00" + "&issueBidNo=201505201235" +
        "&merchantNo=708732" + "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&submitBidNo=201505201235-1"+
        "&timestamp=" + timestamp + "&userName=hjhang_sunmin"
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            $("#TouBiaosign").val(data);
            $("#TouBiaoForm").submit();
        },
        data: "sign=" + sign,
    });
}

//撤销用户投标,暂时只支持众筹的标
function CheXiaoTouBiao() {
    $.ajax({
        url: "/Account/CheXiaoTouBiao",
        type: "Post",
        success: function (data) {
            alert(data);
        },//金额，
        data: "merchantNo=708732" + "&issueBidNo=201505201235" + "&submitBidNo=201505201235-1",
    });
}

//自动投标
function ZiDongTouBiao() {
    $.ajax({
        url: "/Account/ZiDongTouBiao",
        type: "Post",
        success: function (data) {
            alert(data);
        },//金额，
        data: "merchantNo=708732" + "&issueBidNo=201505201235" + "&submitBidNo=201505201235-1" + "&creditUserName=hjhang_sunmin"+
            "&creditAmount=10.00" + "&discountAmount=1.00" + "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister",
    });
}

//流标
function LiuBiao() {
    $.ajax({
        url: "/Account/LiuBiao",
        type: "Post",
        success: function (data) {
            alert(data);
        },//金额，
        data: "merchantNo=708732" + "&issueBidNo=201505201235" + "&eventType=1" + "&platformFee=0.00" + "&dealerMerchantNo=708732" +
            "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister",
    });
}

//用户还款
function YongHuHuanKuan() {
    //先将顺序拼接好
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#YongHuHuanKuantimestamp").val(timestamp);
    var sign = "callback=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&isReward=1" + "&issueBidNo=201505201235" +
        "&merchantNo=708732" + "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&repaymentAmount=100.00"
        + "&repaymentMode=1" + "&repaymentNo=201505201235-6" + "&repaymentType=1" + "&timestamp=" + timestamp +
        "&transferItems=hjhang_sunmin:100.00:0.00:1" +"&userName=hjhang_sunmin";
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign",
        type: "Post",
        success: function (data) {
            $("#YongHuHuanKuansign").val(data);
            $("#YongHuHuanKuanForm").submit();
        },
        data: "sign=" + sign,
    });
}

//债权转让（个人）
function ZhaiQuanZhuanRang() {
    //先将顺序拼接好
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#ZhaiQuanZhuanRangtimestamp").val(timestamp);
    var sign = "assignmentNo=201505221" + "&issueBidNo=201505201235" + "&merchantNo=708732" +
        "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&pageUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" +
        "&parValue=100.00" + "&payExpire=60" + "&payableAmount=100.00" + "&payeeFee=0.00" + "&payeeUserName=hjhang_huangjiang" + "&payerFee=0.00" +
        "&payerUserName=hjhang_sunmin" + "&timestamp=" + timestamp;
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            $("#ZhaiQuanZhuanRangsign").val(data);
            $("#ZhaiQuanZhuanRangForm").submit();
        },
        data: "sign=" + sign,
    });
}

//债权收购
function ZhaiQuanShouGou() {
    $.ajax({
        url: "/Account/ZhaiQuanShouGou",
        type: "Post",
        success: function (data) {
            alert(data);
        },
        data: "notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" +"&assignmentNo=123432175124"+"&assignmentFundNo=dasdgjjhy"+
            "&parValue=100.00" + "&payableAmount=100.00" + "&payerUserName=hjhang_sunmin" + "&payerFee=0.00" + "&payeeUserName=hjhang_huangjiang" +
            "&payeeFee=0.00" + "&issueBidNo=201505201239",
    });
}

//资金冻结（债权收购）
function ZiJinDongJie() {
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#ZiJinDongJietimestamp").val(timestamp);
    var sign = "merchantNo=708732" + "&assignmentFundNo=2015052221" + "&userName=hjhang_sunmin" +
        "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&pageUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" +
        "&frozenAmount=1.00" + "&memo=wu" + "&payExpire=5" + "&timestamp=" + timestamp;
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            $("#ZiJinDongJiesign").val(data);
            $("#ZiJinDongJieForm").submit();
        },
        data: "sign=" + sign,
    });
}

//资金解冻
function ZiJinJieDong() {
    $.ajax({
        url: "/Account/ZiJinJieDong",
        type: "Post",
        success: function (data) {
            alert(data);
        },
        data: "notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&assignmentFundNo=1234dede4f" + "&unfrozenAmount=1.00" +
            "&memo=wu",
    });
}

//平台满标分润
function PingTaiManBiao() {
    $.ajax({
        url: "/Account/PingTaiManBiao",
        type: "Post",
        success: function (data) {
            alert(data);
        },
        data: "issueBidNo=20150521",
    });
}

//设置众筹项目发标机构
function SheZhiZhongChou() {
    $.ajax({
        url: "/Account/SheZhiZhongChou",
        type: "Post",
        success: function (data) {
            alert(data);
        },
        data: "issueBidNo=201505223659" + "&projectName=201505219842" + "&debitInstitutionNo=zanwu123" + "&businessLicenseNo=12321" + "&contactPerson=sdwee" +
            "&contactPersonTel=15601887123",
    });
}

//创建融资接口
function ChuangJianRongZi() {
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#ChuangJianRongZitimestamp").val(timestamp);
    var sign = "merchantNo=708732" + "&financingNo=20150522" + "&userName=hjhang_sunmin" +
        "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&callback=http://www.hjhang.com/Account/AfterShengFuTongRegister" +
        "&securityAmount=1.00" + "&financingAmount=100.00" + "&timestamp=" + timestamp;
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            $("#ChuangJianRongZisign").val(data);
            $("#ChuangJianRongZiForm").submit();
        },
        data: "sign=" + sign,
    });
}

//撤销融资接口
function CheXiaoRongZi() {
    $.ajax({
        url: "/Account/CheXiaoRongZi",
        type: "Post",
        success: function (data) {
            alert(data);
        },
        data: "financingNo=201505223659" + "&userName=hjhang_sunmin" + "&securityAmount=1.00" ,
    });
}

//补充保证金
function BuChongBaoZhengJin() {
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#BuChongBaoZhengJintimestamp").val(timestamp);
    var sign = "merchantNo=708732" + "&financingNo=20150522" + "&marginCallNo=20150523" + "&userName=hjhang_sunmin" + "&traderUser=1234" +
        "&marginCallAmount=1.00" + "&platformFee=2.00"+
        "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&callback=http://www.hjhang.com/Account/AfterShengFuTongRegister" +
        "&timestamp=" + timestamp;
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            $("#BuChongBaoZhengJinsign").val(data);
            $("#BuChongBaoZhengJinForm").submit();
        },
        data: "sign=" + sign,
    });
}

//融资投资接口
function RongZiTouZi(){
    $.ajax({
        url: "/Account/RongZiTouZi",
        type: "Post",
        success: function (data) {
            alert(data);
        },
        data: "financingNo=2015052236dew9" + "&investNo=sdef3eds" + "&userName=hjhang_sunmin" + "&traderUser=sdwddfrt" + "&investAmount=1.00"+
            "&platformFee=1.00" + "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister",
    });
}

//用户补还款
function YongHuBuHuanKuan() {
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#YongHuBuHuanKuantimestamp").val(timestamp);
    var sign = "merchantNo=708732" + "&timestamp=" + timestamp + "&userName=hjhang_sunmin" + "&origOrderType=1" + "&origOrderNo=1234565" +
        "&compensationNo=12345652234" + "&paymentAmount=1.00" + "&interestAmount=2.00" + "&platformFee=3.00" +
        "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" + "&callback=http://www.hjhang.com/Account/AfterShengFuTongRegister";
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            $("#YongHuBuHuanKuansign").val(data);
            $("#YongHuBuHuanKuanForm").submit();
        },
        data: "sign=" + sign,
    });
}

//购买平台服务
function GouMaiPingTaiFuWu() {
    var myDate = new Date();
    var timestamp = TimeFormat();
    $("#GouMaiPingTaiFuWutimestamp").val(timestamp);
    var sign = "merchantNo=708732" + "&timestamp=" + timestamp + "&userName=hjhang_sunmin" + "&transferNo=123456" + "&transferAmount=1.00" +
        "&transferMemo=wu"+"&pageUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister" +
        "&notifyUrl=http://www.hjhang.com/Account/AfterShengFuTongRegister";
    sign = sign.replace(/\&/g, "|");
    $.ajax({
        url: "/Account/GetSign2",
        type: "Post",
        success: function (data) {
            $("#GouMaiPingTaiFuWusign").val(data);
            $("#GouMaiPingTaiFuWuForm").submit();
        },
        data: "sign=" + sign,
    });
}

